home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Headers / gamekit / GKActor.h < prev    next >
Text File  |  1995-06-12  |  5KB  |  97 lines

  1.  
  2. // This is an Abstract Class from which sprites may be derived.
  3. // This basically provides basic variables to hold location and the
  4. // necessary methods to access the location instance variables. For
  5. // basic funtionality, -move: and -drawActorWithOffset: need to be
  6. // overridden.  -move: should change nextLocation to tell the object
  7. // where to move to and -drawActorWithOffset: should be able to draw
  8. // a representation of the GKActor.  Note that actual movement happens
  9. // when -moveOneFrame is called; -renderAt:move: will therefor call
  10. // the -moveOneFrame method if move:YES is chosen.
  11. // A simple form of animation is provided which you may use with the
  12. // need to write a -drawActorWithOffset: method, if you like.  It uses
  13. // the idea of a "series" and "frames" within that series.  What you
  14. // do is make a .tiff image with all the frames of animation.  Since
  15. // a given actor will look different, say, depending upon the direction
  16. // it is moving, you have a series of frames for each appearance.  In
  17. // the .tiff, each series is a horizontal strip of the .tiff and they
  18. // are numbered with series zero at the bottom, higher numbered series
  19. // are above lower numbered series.  The frames are numbered starting
  20. // with zero at the left side, higher frame numbers to the right.
  21. // Note that all series MUST be the same height and all frames the
  22. // same width!  You set the width/height using the -setSize: method.
  23.  
  24. #import <appkit/appkit.h>
  25.  
  26. #define GK_DEFAULT_ACTOR_WIDTH    16
  27. #define GK_DEFAULT_ACTOR_HEIGHT    16
  28. #define GK_DEAD_ACTOR    0
  29.  
  30. // Warning:  take note of this #define--it fakes an instance variable for us.
  31. #define GK_location (boundingBox.origin)    // an NXPoint; our current location
  32. // It's here rather than in the .m files because it may be handy for
  33. // use when writing subclasses...
  34.  
  35. @interface GKActor:Object
  36. {
  37.     id renderedImage;    // NXImage
  38.     id stage;            // the stage the actor is on .. there can only be one
  39.     int drawingLevel;    // drawing level on the stage
  40.     NXPoint nextLocation, lastLocation, lastDrawnLocation;
  41.     NXRect boundingBox;    // Actor's bounding box (embodies current location)
  42.     int series, frame, cycles, maxSeries, state;
  43.     int *maxFrames;
  44.     BOOL movedThisFrame;    // did we move or are we stationary?  Set to YES
  45.         // automatically if the actor moved, but you should set this to YES
  46.         // yourself if in an overridden -updateDrawingState method and you
  47.         // changed the actor's appearance such that it needs a redraw
  48. }
  49.  
  50. - init;                // initialize the new instance vars
  51.  
  52. // configuring the basic actor...
  53. - setSize:(const NXSize *)aSize; // set actor's size (enclosing frame in image)
  54. - setRenderedImage:anImage;    // set the bitmap image used to render
  55. - setSeries:(int)anInt;        // set the animation series (row) to use in bitmap
  56. - setMaxFrames:(const int *)anIntArray count:(int)anInt; // array indexed by
  57.         // series number; gives the number of frames in the series.  The
  58.         // input array is copied, so free it when you're done with it
  59. - (int)drawingLevel;
  60. - setDrawingLevel:(int)aLevel;
  61. - stage;
  62. - setStage:aStage;
  63.  
  64. // Moving the actor - you usually won't call these but do override -move:
  65. - move:sender;        // Move the actor one animation frame
  66. - moveOneFrame;        // makes the animation advance one step.  Call -move:
  67.                     // first to set up params.  (Called by -renderAt:move:)
  68. - leaveTheStage;    // get the actor off the stage and into the "free" list
  69.  
  70. // Handling collisions
  71. - (int)collisionType;    // called to determine type of collision shape
  72. - (void *)shapeStruct;    // return pointer to the collision shape
  73. - collidedWith:anActor;    // called when it is detected that we hit something
  74.         // right now does nothing.
  75.  
  76. // getting info about the GKActor
  77. - lastAt:(NXPoint *)aPoint;            // to find out where actor was last located
  78. - lastDrawnAt:(NXPoint *)aPoint;    // to find out where actor was last drawn
  79. - at:(NXPoint *)aPoint;                // where is the actor now?
  80. - getBoundingBox:(NXRect *)box;        // obtain the bounding box
  81. - (int)series;                        // the series we're currently using
  82. - (int)frame;                        // the next frame that will be drawn
  83.  
  84. // drawing the actor and advancing the internal state machine
  85. - eraseInDirtPile:dirtPile;
  86. - markInDirtPile:dirtPile;    // same as above but called at different times
  87. - renderAt:(NXPoint *)offset move:(BOOL)moveOk withDirtPile:dirtPile;
  88.         // do movement (possibly) and do the render/draw
  89.         // you should lock focus on view that gets the image before calling.
  90.         // use offset=NULL if no offset is needed.
  91. - drawActorWithOffset:(NXPoint *)offset;    // draw the actor
  92.         // here's what you override to change the way it's drawn.
  93.         // offset MUST be non-NULL, unlike -renderAt:move:
  94. - updateDrawingState;    // called after drawing to advance frames, etc.
  95.  
  96. @end
  97.